home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Educational Software Cooperative 4
/
Educational Software Cooperative 4.iso
/
lights22
/
weep.cpr
/
SS_CDEM2.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-06-22
|
3KB
|
189 lines
#include <windows.h>
/* Prototyp für Funktion aus lm_util.dll */
BYTE FAR PASCAL LgdDefProc (LPLONG lRet, HWND hWnd, WORD msg, WORD wParam, LONG lParam);
/* Globale Variable */
/* suboptimale lösung, aber egal ... */
LONG fExit;
LONG lEndTime;
#define DUMMYREFERENCE(a) (a)=(a)
typedef struct tagGLOBALS
{
HANDLE hInstance;
} GLOBALS;
extern GLOBALS globaldata;
#define APPNAME "cBlackness"
/* WindowProc des Bildschirmschoners */
/* In der Regel wird der Schoner über WM_TIMER bzw. über PeekMessage bestimmte
Zeichenaktionen ausloesen.
*/
LONG FAR _export PASCAL WindowProc (HWND hwnd, WORD msg, WORD wParam, LONG lParam)
{
PAINTSTRUCT ps;
HDC dc;
LONG lRet;
if (LgdDefProc (&lRet, hwnd, msg, wParam, lParam))
{
return lRet;
}
switch (msg)
{
case WM_PAINT:
dc = BeginPaint (hwnd, &ps);
DUMMYREFERENCE (dc);
EndPaint (hwnd, &ps);
break;
/*case WM_CREATE:*/
/* case WM_ERASEBKGND:
return 1;
*/ /* bildschirm stehen lassen */
case WM_SIZE:
/* cxClient = LOWORD (lParam);
cyClient = HIWORD (lParam);*/
break;
case WM_TIMER:
if (GetCurrentTime () >= lEndTime)
{
fExit = 0;
DestroyWindow (hwnd);
}
break;
case WM_KILLFOCUS:
if (fExit == -1)
{
fExit = 2;
DestroyWindow (hwnd);
}
break;
case WM_KEYDOWN: /* jeder tastendruck beendet den Saver */
case WM_CLOSE:
case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN:
fExit = 1; /* randomizer mu▀ zwischen timeout und abbruch unterscheiden k÷nnen! */
DestroyWindow (hwnd);
break;
case WM_DESTROY:
KillTimer (hwnd, 1000);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
LONG Blackness (LONG lDuration, LONG lFlags)
{
HWND hwnd;
MSG msg;
int i, cCursor;
WNDCLASS wndclass;
DUMMYREFERENCE (lFlags);
fExit = -1;
if (TRUE)
{
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WindowProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = globaldata.hInstance;
wndclass.hIcon = 0;
wndclass.hCursor = LoadCursor(0, IDC_CROSS);
wndclass.hbrBackground= GetStockObject(BLACK_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName= APPNAME;
if (!RegisterClass(&wndclass))
{
}
}
hwnd = CreateWindow(
APPNAME,
APPNAME,
WS_POPUP | WS_BORDER,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
0,
0,
globaldata.hInstance,
NULL);
UpdateWindow(hwnd);
SetWindowPos (hwnd, 0, -1, -1,
GetSystemMetrics (SM_CXSCREEN)+2,
GetSystemMetrics (SM_CYSCREEN)+2,
SWP_NOZORDER);
ShowWindow (hwnd, SW_NORMAL);
cCursor = 0;
do
{
i = ShowCursor (FALSE);
cCursor++;
}
while (i >= 0);
if (lDuration > 0)
{
lEndTime = GetCurrentTime () + lDuration * 1000;
}
else
{
lEndTime = 0x7fffffffL;
}
SetTimer (hwnd, 1000, 1, NULL);
while (GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
while (cCursor > 0)
{
ShowCursor (TRUE);
cCursor--;
}
UnregisterClass (APPNAME, globaldata.hInstance);
return fExit;
}